//
//  CDAgreementViewController.m
//  CollectToDesktop
//
//  Created by 王启颖 on 2020/10/19.
//  Copyright © 2020 godbe. All rights reserved.
//

#import "CDAgreementViewController.h"
#import <WebKit/WebKit.h>
@interface CDAgreementViewController ()<WKUIDelegate,WKNavigationDelegate>
@property (strong, nonatomic) WKWebView *webView;
@end

@implementation CDAgreementViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    WKWebViewConfiguration *config = [[WKWebViewConfiguration alloc] init];
    _webView = [[WKWebView alloc] initWithFrame:self.view.bounds configuration:config];
    // UI代理
    _webView.UIDelegate = self;
    // 导航代理
    _webView.navigationDelegate = self;
    // 是否允许手势左滑返回上一级, 类似导航控制的左滑返回
    _webView.allowsBackForwardNavigationGestures = YES;
    [self.view addSubview:_webView];

    [self request];
    
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    [button setImage:[UIImage imageNamed:@"返 回(2)"] forState:UIControlStateNormal];
    [button setFrame:CGRectMake(0, 0, 60, 40)];
    button.contentEdgeInsets = UIEdgeInsetsMake(0, -20,0, 0);
    [button addTarget:self action:@selector(navigationItemBack) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithCustomView:button];
    self.navigationItem.leftBarButtonItem =  item;
}

-(void)navigationItemBack{
    [self.navigationController popViewControllerAnimated:YES];
}

#pragma mark - 网络请求
-(void)request{

    NSString *urlstr=[NSString stringWithFormat:@"https://gapi.szlzyd.com/0010/np/product/agreement"];
    [[CDNetworkRequset HttpRequstManager] PostURL:urlstr params:[[NSMutableDictionary alloc]init] success:^(NSInteger code, id  _Nonnull result) {

        NSArray *arr = result[@"data"];
        NSDictionary *dic = arr[0];
        [_webView loadHTMLString:dic[@"a_0"] baseURL:nil];
    } fail:^(NSError * _Nonnull error) {
        
    }];
}

@end
